import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import junit.framework.TestCase;


public class TestTriangleSolver extends TestCase{
	
	private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
	private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
	
	//@before
	public void setUpStreams() {
	    System.setOut(new PrintStream(outContent));
	    System.setErr(new PrintStream(errContent));
	}

	public void test_no_args(){
		
		setUpStreams();
		Triangle.main(null);
		assertEquals("Usage: Triangle <command> a b c\n", outContent.toString());
		cleanUpStreams();
		
	}
	
	public void test_less_4args(){
		
		setUpStreams();
		String args[] = {"class", "4.2334", "32.23"};
		Triangle.main(args);
		assertEquals("Usage: Triangle <command> a b c\n", outContent.toString());
		cleanUpStreams();
		
	}
	
	public void test_more_4args(){
		
		setUpStreams();
		String args[] = {"type", "4.2334", "32.23","3.244","1.442"};
		Triangle.main(args);
		assertEquals("Usage: Triangle <command> a b c\n", outContent.toString());
		cleanUpStreams();
		
	}
	
	public void test_out_of_range_high(){
		
		setUpStreams();
		String args[] = {"class", "1e31","1e31","1e31"};
		Triangle.main(args);
		assertEquals("Usage: Triangle <command> a b c\na b c < 10E30\n", outContent.toString());
		cleanUpStreams();
		
	}
	
	public void test_out_of_range_low(){
		
		setUpStreams();
		String args[] = {"class", "-4","-2","-1"};
		Triangle.main(args);
		assertEquals("Usage: Triangle <command> a b c\na b c > 0\n", outContent.toString());
		cleanUpStreams();
		
	}
	
	public void test_invalid_command(){
		
		setUpStreams();
		String args[] = {"random_command", "3","4","5"};
		Triangle.main(args);
		assertEquals("Usage: Triangle <command> a b c\n<command> must be either type, class, or angles\n", outContent.toString());
		cleanUpStreams();
		
	}
	
	public void test_not_triangle(){
		assertFalse(Triangle.isTriangle(1.1F,10.5F,40.53F));
	}
	//@After
	public void cleanUpStreams() {
	    System.setOut(null);
	    System.setErr(null);
	}
}
